<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />    
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script></head>
    <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
</head>
<body>
    <header class="header header-f" style="padding-top:2rem; height:4rem;">
        <div class="header-l aui-pull-left" onclick="closeWin()">
            <i class="fa fa-angle-left"></i>
        </div>
        <div class="header-title">
            编辑资料
        </div>
        <div class="header-r aui-pull-right">
        </div>
    </header>
    <div style="height:4rem;"></div>

    <div class="aui-content aui-margin-b-15">
        <div id="list">
            <!-- <ul class="aui-list aui-list-in">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">
                            手机号：
                        </div>
                        <div class="aui-list-item-input">
                            <input type="number" placeholder="请输入手机号" id="tel">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">
                            昵称：
                        </div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请输入昵称" id="nickname">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">
                            邮箱：
                        </div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请输入您的邮箱" id="email">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">
                            省：
                        </div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请输入您的出生日期" id="province">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">
                            市：
                        </div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请输入您的出生日期" id="city">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">
                            区：
                        </div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请输入您的出生日期" id="region">
                        </div>
                    </div>
                </li>
            </ul> -->
        </div>
    </div>

    <div class="aui-content-padded">
        <div class="aui-btn aui-btn-danger aui-btn-block aui-btn-sm" onclick="change();">确认修改</div>
    </div>


</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/template" id="template">
    <ul class="aui-list aui-list-in">
        <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label">
                    手机号：
                </div>
                <div class="aui-list-item-input">
                    <input type="number" value="{{=it.tel}}" id="tel">
                </div>
            </div>
        </li>
        <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label">
                    昵称：
                </div>
                <div class="aui-list-item-input">
                    <input type="text" value="{{=it.nickname}}" id="nickname">
                </div>
            </div>
        </li>
        <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label">
                    邮箱：
                </div>
                <div class="aui-list-item-input">
                    <input type="text" value="{{=it.email}}" id="email">
                </div>
            </div>
        </li>
        <li class="aui-list-item">
            <div class="aui-list-item-inner" id="addressView">
                <div class="aui-list-item-label">
                    地址：
                </div>
                <div class="aui-list-item-input" id="city">
                    {{=it.province}} {{=it.city}} {{=it.region}}
                </div>
            </div>
        </li>
<!--         <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label">
                    省：
                </div>
                <div class="aui-list-item-input">
                    <input type="text" placeholder="{{=it.province}}" id="province">
                </div>
            </div>
        </li>
        <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label">
                    市：
                </div>
                <div class="aui-list-item-input">
                    <input type="text" placeholder="{{=it.city}}" id="city">
                </div>
            </div>
        </li>
        <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label">
                    区：
                </div>
                <div class="aui-list-item-input">
                    <input type="text" placeholder="{{=it.region}}" id="region">
                </div>
            </div>
        </li> -->
    </ul>
</script>
<script type="text/javascript">
    apiready = function(){
      loadData();



  }

  function loadData(){
    var userid = $api.getStorage('userid');
    var authtoken = $api.getStorage('authtoken');
    api.ajax({
        url: webAddress + '/a/member/Member/info',
        method: 'post',
        data: {
            values: {
            },
        },
        headers: {
            TOKEN: token,
            authuid: userid,
            authtoken: authtoken,
            'Content-Type': 'application/x-www-form-urlencoded',
        },
    },function(ret, err){
        if (ret) {
                // alert( JSON.stringify( ret ) );
                proName = ret.result.province;
                cityName = ret.result.city;
                dirName = ret.result.region;
                if (ret.result) {
                    templateFun(ret.result);
                }
            } else {
                // alert( JSON.stringify( err ) );
                api.toast({
                    msg: err.body.message,
                    duration: 2000,
                    location: 'bottom',
                    global: 'true',
                });
                return false;
            }
        });
}

    // 模板赋值函数
    function templateFun(data){
        if (data) {
          var template = $api.byId('template');
          var dotFn = doT.template(template.innerHTML);
          var html = dotFn(data);
          var list = $api.byId('list');
          $api.html(list, html);
          loadAddressView();
      }else{

          var list = $api.byId('list');
          var html = '<h2 style="padding:1rem; text-align:center; color:#999; font-size:1rem;">暂无内容</h2>';
          list.innerHTML = html;
      }
  }

    // 加载省市区控件
  function loadAddressView(){
      var addressView = api.require('addressView');
      addressView.open({
        file_addr: 'widget://res/district.txt', //数据源地址
        selected_color: '#ff0000', //颜色
        pro_id: 110000, //省id
        city_id: 110100, //市id
        dir_id: 110101 //区id
    });
      $api.addEvt($api.byId("addressView"), 'click', function() {
        addressView.show({}, function(ret, err) {
            if (ret.status) {
                // alert(JSON.stringify(ret)); //返回值
                var data = ret.data;
                proName = data[0].name;
                cityName = data[1].name;
                dirName = data[2].name;
                var address = proName + ' ' + cityName + ' ' + dirName;
                $('#city').html(address);
            }
        });
    });
  }


  function change(){
    var userid = $api.getStorage('userid');
    var authtoken = $api.getStorage('authtoken');
    var tel = $api.byId('tel').value;
    var nickname = $api.byId('nickname').value;
    var email = $api.byId('email').value;

    api.ajax({
        url: webAddress + '/a/member/Member/update',
        method: 'post',
        data: {
            values: {
                tel: tel,
                nickname: nickname,
                email: email,
                province: proName,
                city: cityName,
                region: dirName,
            },
        },
        headers: {
            TOKEN: token,
            authuid: userid,
            authtoken: authtoken,
            'Content-Type': 'application/x-www-form-urlencoded',
        },
    },function(ret, err){
        if (ret) {
            // alert( JSON.stringify( ret ) );
            api.toast({
                msg: ret.message,
                duration: 2000,
                location: 'bottom',
                global: 'true',
            });
            api.sendEvent({
                name: 'reload'
            });
            api.closeWin();
        } else {
            // alert( JSON.stringify( err ) );
            api.toast({
                msg: ret.message,
                duration: 2000,
                location: 'bottom',
                global: 'true',
            });
        }
    });
}


function openClub(){
    var delay = 0;
    if(api.systemType != 'ios'){
        delay = 300;
    }
    api.openWin({
        name: 'club_win',
        url: './html/club_win.html',
        bounces:false,
        delay: delay,
        slidBackEnabled:true,
        vScrollBarEnabled:false,
        progress:{
            type:"page"
        }
    });
}

function closeWin(){
    api.closeWin({
    });
}
</script>
</html>